{include file='common/head' /}
<body>
<div class="x-nav">
          <span class="layui-breadcrumb">
              <a><cite>系统管理</cite></a>
              <a><cite>角色管理</cite></a>
          </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5">
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="name"  placeholder="请输入角色名称" autocomplete="off" class="layui-input" value="{$get.name|default=''}">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
                        </div>
                    </form>
                </div>
                <div class="layui-card-header">
                    <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="iconfont">&#xe69d;</i> 批量删除</button>
                    <button class="layui-btn" onclick="xadmin.open('添加角色','/admin/system/role_edit','','',true)"><i class="layui-icon"></i>角色</button>
                    <span style="line-height:40px;float: right;">共有数据：{$count} 条</span>
                </div>
                <div class="layui-card-body layui-table-body layui-table-main">
                    <table class="layui-table layui-form">
                        <thead>
                        <tr>
                            <th style="text-align: center;width: 5%">
                                <input type="checkbox" lay-filter="checkall" name="" lay-skin="primary">
                            </th>
                            <th style="text-align: center;width: 15%;">角色名称</th>
                            <th style="text-align: center;width: 60%;">角色描述</th>
                            <th style="text-align: center;width: 20%;">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        {volist name="list" id="v"}
                        <tr>
                            <td style="text-align: center;">
                                <input type="checkbox" name="id" value="{$v.id}" lay-skin="primary">
                            </td>
                            <td style="text-align: center;">{$v.name}</td>
                            <td style="text-align: center;">{$v.desc}</td>
                            <td style="text-align: center;">
                                <button class="layui-btn layui-btn layui-btn-xs" title="编辑"  onclick="xadmin.open('编辑','/admin/system/role_edit?id={$v.id}','','',true)" href="javascript:;">
                                    <i class="layui-icon">&#xe642;</i>编辑
                                </button>
                                <button class="layui-btn-danger layui-btn layui-btn-xs" title="删除" onclick="member_del(this,'{$v.id}')" href="javascript:;">
                                    <i class="layui-icon">&#xe640;</i>删除
                                </button>
                            </td>
                        </tr>
                        {/volist}
                        </tbody>
                    </table>
                </div>
                <div class="layui-card-body ">
                    <div class="page">
                        {$page}
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    layui.use(['form'], function(){
        var  form = layui.form;

        // 监听全选
        form.on('checkbox(checkall)', function(data){
            if(data.elem.checked){
                $('tbody input').prop('checked',true);
            }else{
                $('tbody input').prop('checked',false);
            }
            form.render('checkbox');
        });
    });

    /*删除*/
    function member_del(obj,id){
        layer.confirm('确认要删除吗？',function(index){
            var ids = [];
            ids.push(id);
            $.ajax({
                url:"{:url('System/role_del')}",
                type: "post",
                data:{id:ids},
                dataType:"json",
                success:function (res) {
                    if(res.code == 200){
                        layer.msg('删除成功', {icon: 1,time:1000});
                        $(obj).parents("tr").remove();
                    }else{
                        layer.alert(res.msg, {icon:2,time:1000});
                    }
                },
                error:function(e){
                    layer.alert("网络错误", {icon:5,time:1000});
                },
            });
        });
    }

    //批量删除
    function delAll (argument) {
        var ids = [];
        // 获取选中的id
        $('tbody input').each(function(index, el) {
            if($(this).prop('checked')){
                ids.push($(this).val())
            }
        });

        layer.confirm('确认要删除吗？',function(index){
            $.ajax({
                url:"{:url('System/role_del')}",
                type: "post",
                data:{id:ids},
                dataType:"json",
                success:function (res) {
                    if(res.code == 200){
                        //捉到所有被选中的，发异步进行删除
                        layer.msg('删除成功', {icon: 1,time:1000});
                        $(".layui-form-checked").not('.header').parents('tr').remove();
                    }else{
                        layer.alert(res.msg, {icon:2,time:1000});
                    }
                },
                error:function(e){
                    layer.alert("网络错误", {icon:5,time:1000});
                },
            });
        });
    }
</script>
{include file='common/footer' /}